package com.bq.server.core.mapper;

import cn.hutool.core.util.StrUtil;
import com.bq.server.base.BaseMapper;
import com.bq.server.base.IdEntity;
import com.bq.server.core.model.Department;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author shchen
 */
public interface DepartmentMapper extends BaseMapper<Department> {

    /**
     * 根据部门名称和父类部门id查询数量
     *
     * @param deptName 部门名称
     * @return 部门信息
     */
    default Integer selectDeptInfo(String deptName, Long parentId) {
        return lambdaQuery()
                .eq(Objects.nonNull(deptName), Department::getDeptName, deptName)
                .eq(Objects.nonNull(parentId), Department::getParentId, parentId)
                .count();
    }

    default Department findInfoById(Long deptId) {
        return lambdaQuery()
                .eq(Objects.nonNull(deptId), Department::getId, deptId)
                .one();
    }

    default List<Department> findInfoByName(String search) {
        if (StrUtil.isEmpty(search)) {
            return new ArrayList<>();
        }
        return lambdaQuery()
                .like(Department::getDeptName, search)
                .list();
    }

}